/*
 * Created on 7/Abr/2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.cyborgas.xmltool.actions;

import java.net.URI;
import java.net.URISyntaxException;

import org.cyborgas.xmltool.MainWindow;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.SWT;

/**
 * @author rino
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class UrlOpenAction extends Action {

	private MainWindow window;

	public UrlOpenAction(MainWindow window) {
		this.window = window;
//		setText("Open &URL...@Ctrl+U");
		setText("Open &URL...");
		setAccelerator(SWT.MOD1 | 'U');
		setToolTipText("Open XML file from URL");
	}

	public void run() {
		InputDialog dialog = new InputDialog(window.getShell(), "Open URL", "Type an URL for an XML document to open", "", null);

		dialog.open();

		String url = dialog.getValue();
		if (url != null && !url.equals("")) {
			URI urlObj;
			try {
				urlObj = new URI(url);
				window.load(urlObj);
			} catch (URISyntaxException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
